<template>
	<view class="fui-wrap">
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index" arrow>
				<view class="item" @click="showAct(item,index)">
					<view class="line">
						<fui-text text="创建时间：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="车牌号：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.plate_number" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="操作人员：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.admin.nickname" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="备注：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.remark" color="black" :size="28"></fui-text>
					</view>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<fui-fab @click="showPopup=true" position="right" :bottom="120" width="70" distance="30">
			<fui-icon name="plus" color="#fff" size="60"></fui-icon>
		</fui-fab>
		<fui-modal :show="showPopup"  descr="添加黑名单" :radius="16" :maskClosable="false" direction="column" @click="clickButton" @cancel="cancelButton">
			<view style="width:85%;margin: 0 auto;">
				<fui-input readonly @click="$navigateTo('parking/plate?type=input&plate_number='+plate_number)" v-model="plate_number" :inputBorder="true" placeholder="请输入车牌号" :size="28" :padding="['16rpx','20rpx']"></fui-input>
				<fui-textarea height="100rpx" :marginTop="10" :textareaBorder="true" v-model="remark" placeholder="请填写备注" size="28" placeholderStyle="font-weight:400" :padding="['20rpx', '20rpx']"></fui-textarea>
			</view>
		</fui-modal>
		<filter :param="param" @confirm="doSubmit"></filter>
		<fui-modal v-if="buttons" :show="act.show" descr="请选择操作" :buttons="buttons" :radius="16" :maskClosable="true" direction="column" @click="clickButton" @cancel="cancelButton"></fui-modal>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				showPopup:false,
				plate_number:'',
				remark:'',
				list:[],
				page:1,
				endData:false,
				param:{
					plate_number:''
				},
				act:{
					show:false,
					index:'',
					item:''
				},
				buttons:[
					{
						text: '删除',
						background: '#da0000',
						value:'delete'
					}
				]
			}
		},
		onLoad(e) {
			this.getList();
		},
		onShow() {
			let plate_number=uni.getStorageSync('plate_number') || '';
			if(plate_number){
				this.plate_number=plate_number;
				uni.setStorageSync('plate_number','');
				if(!this.showPopup){
					this.showPopup=true;
				}
			}
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('parking/cars/blacklist',{
					...this.param,
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			},
			showAct:function(item,index){
				this.act={
					show:true,
					index:index,
					item:item
				};
			},
			clickButton:function(e){
				let text=e.text;
				if(text=='删除'){
					this.$post('parking/cars/del-black',{plate_number:this.act.item.plate_number},true,true).then(res=>{
						this.cancelButton();
						this.list.splice(this.act.index,1);
					});
				}
				if(text=='取消'){
					this.cancelButton();
				}
				if(text=='确定'){
					if(!this.plate_number){
						this.$msg('请输入车牌号');
						return;
					}
					if(!this.remark){
						this.$msg('请输入拉黑原因');
						return;
					}
					this.$post('parking/cars/add-black',{plate_number:this.plate_number,remark:this.remark},true,true).then(res=>{
						this.cancelButton();
						this.doSubmit({
							plate_number:''
						});
					});
				}
			},
			cancelButton:function(){
				this.showPopup=false;
				this.plate_number='';
				this.remark='';
				this.act={
					show:false,
					index:'',
					item:''
				};
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	display: flex;
	flex-wrap: wrap;
	.line{
		display: flex;
		align-items: center;
		width:100%;
		height: 60rpx;	
	}
}
</style>